package com.zhicheng.mapper;

import com.zhicheng.pojo.AddressBook;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface AddressBookMapper {

    @Select("select * from address_book where user_id = #{userId}")
    List<AddressBook> getByUserId(Long userId);

    @Insert("insert into address_book(user_id, consignee, phone, province_name, city_name, district_name, detail, label, is_default)" +
            "values (#{userId},#{consignee},#{phone},#{provinceName},#{cityName},#{districtName},#{detail},#{label},#{isDefault})")
    void addAddress(AddressBook addressBook);

    @Select("select * from address_book where id = #{addressId}")
    AddressBook getByAddressId(Long addressId);

    void updateAddress(AddressBook addressBook);

    @Delete("delete from address_book where id = #{id};")
    void deleteAddress(Long id);
}
